Numerical Recipes in C: The Art of Scientific Computing $47.50
from:
Cambridge University Press
Orders Department
110 Midland Avenue
Port Chester, NY 10573
1-(800)-227-0247
The VideoToolbox routines that use the recipes assume that you have made the following five changes to the Numerical Recipes in C routines:
1.In every file, change "float" to "FLOAT", and add "#include <nr.h>" at the beginning. Insert the statement "typedef double FLOAT;" in the file nr.h. This is because the Macintosh computes doubles much faster than floats. If you'd rather run slowly than modify your Numerical Recipes files, then you will need to insert "typedef float FLOAT;" in CalibrateLuminance.c and PsychometricFit.c in order to compile those files. The rest of the VideoToolbox doesn't care.
2. In order to produce reasonable polynomial fits it is necessary to reduce the TOL parameter in the file SVDFIT.C to a small value, e.g. 1.0e-14. Otherwise the fits will not be very good, and will have the nonintuitive property that the fit will get WORSE as the order of the polynomial is increased.
3. Fix a very subtle bug in BNLDEV.C. Near the end of the program appears the innocuos looking statement,
if (p != pp) bnl=n-bnl;
However, while p and pp are both declared "float", p is a local variable and pp is an argument. This difference matters, because, under the rules of ANSI C compilers, if the function has an old-style header (i.e. the argument declarations are separate statements rather than inside the parentheses) then the argument is silently "promoted" to double. So pp is actually a double. The consequence is that p is initialized to a truncated version of pp, and the test may fail even though p had not been modified since being assigned pp's value. The fix is trivial, replace the offending statement by this:
if (pp>0.5) bnl=n-bnl; /* this fixs the bug in BNLDEV.C */
(This bug won't bite you if you make the change I suggest in 1. above, i.e. change all instances of float to FLOAT, which you then typedef as double, because then p and pp will both be double. However, I suggest you still implement the bug fix. It won't do any harm.) I notified the authors of Numerical Recipes of this bug several years ago.
4. Correct an error in nr.h. In the ANSI prototype for linmin() change the last argument from "FLOAT (*func)(FLOAT)" to "FLOAT (*func)(FLOAT *)".
5. The strict typechecking of THINK C 5 requires more explicit prototypes. In F1DIM.C change "extern FLOAT *pcom,*xicom,(*nrfunc)();" to "extern FLOAT *pcom,*xicom,(*nrfunc)(FLOAT *);"